type 'a mult_tree = T of 'a * 'a mult_tree list;;

(* 模式匹配只作用于function引入的第二个参数 *)
let rec add_lispy buf = function
    | T(c, []) -> Buffer.add_char buf c
    | T(c, sub) ->
       Buffer.add_char buf '(';
       Buffer.add_char buf c;
       List.iter (fun t -> Buffer.add_char buf ' '; add_lispy buf t) sub;
       Buffer.add_char buf ')'

let lispy t =
    let buf = Buffer.create 128 in
    add_lispy buf t;
    Buffer.contents buf;;

let t = T('a', [T('f',[T('g',[])]); T('c',[]);
    T('b',[T('d',[]); T('e',[])])]);;

lispy t;;  (* output (a (f g) c (b d e)) *)